# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: maz-1 <loveayawaka@gmail.com>

pkgbase=ndiswrapper
pkgname=(ndiswrapper-dkms ndiswrapper)
pkgver=1.62
pkgrel=4
pkgdesc="Module for NDIS (Windows Network Drivers) drivers supplied by vendors"
arch=('loong64' 'x86_64')
url="https://sourceforge.net/projects/ndiswrapper/"
license=('GPL')
source=("https://sourceforge.net/projects/ndiswrapper/files/stable/ndiswrapper-$pkgver.tar.gz"
        'kernel-5.3.patch' 'kernel-5.4.patch' 'kernel-5.5.patch' 'kernel-5.6.patch'
        'dkms.conf')
sha512sums=('a6e111bc699572642e44d6d31cc2f06374648a01b8dd7dd4e74d6ad5e187e39f99faee38f792c83a94d4618ae4d8866914fb3f60b1d80e838a753285ea7cf783'
            'c404f35280534b172235c5c578657d7a30ac2253c7c2abedd65a183d09390e95e7c3030cb409accb4d198ff0411482f8029f8664418c99d5672f92e9c733801d'
            '36450042db79ed4545030276bff9db1bc9895259f38c1c0bf4dc238ad76ec61c2e08d437997dafd327f2a8fd1694d61e418941555e92144e3ec86c8066561429'
            'ed543cbfb236de0a20e1f164c22c83cd19aec416b5f50a58cee731857231c667d166c36814047174bddda36261af71e92ecdb2944e5b818a603085af279fbd89'
            'f37efd16a32c4a36607d43ccda0979a914521157e2095db4c331315638f24d440d8628ea7e98c96f92155e1df133478f0ce9eb76152e963eca4a3fecafbca155'
            '9fce255fc02ddf6e939dc61a5e29c0ea5fa1a31ecc3c390081bc53aa1cd48eddf5db621f0a1cb909634529d4ccc2995eea8827be8eb5807b34dc17e15045ecf4')

prepare() {
  cd ndiswrapper-$pkgver
  patch --no-backup-if-mismatch -p2 -i "$srcdir"/kernel-5.3.patch
  patch --no-backup-if-mismatch -p1 -i "$srcdir"/kernel-5.4.patch
  patch --no-backup-if-mismatch -p1 -i "$srcdir"/kernel-5.5.patch
  patch --no-backup-if-mismatch -p1 -i "$srcdir"/kernel-5.6.patch
}

build() {
  cd ndiswrapper-$pkgver
  make -C utils
}

package_ndiswrapper-dkms() {
  depends=('dkms')
  provides=('NDISWRAPPER-MODULE')
  conflicts=('NDISWRAPPER-MODULE')

  cd ndiswrapper-$pkgver
  mkdir -p "$pkgdir"/usr/src
  cp -RL ./driver "$pkgdir"/usr/src/ndiswrapper-$pkgver
  cp "$srcdir"/dkms.conf "$pkgdir"/usr/src/ndiswrapper-$pkgver
}

package_ndiswrapper() {
  depends=('perl' 'NDISWRAPPER-MODULE')

  cd ndiswrapper-$pkgver
  make -C utils sbindir=/usr/bin usrsbindir=/usr/bin DESTDIR="$pkgdir" install
}
